#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//reverse:将容器内元素进行反转
//函数原型：reverse(iterator beg, iterator end);
//反转指定范围的元素
//beg 开始迭代器   end 结束迭代器

class myPrint {
public:
    void operator()(int val) {
        cout << val << " ";
    }
};

void test() {
    vector<int> v;
    v.push_back(10);
    v.push_back(30);
    v.push_back(50);
    v.push_back(40);
    v.push_back(20);

    cout << "反转前：" << endl;
    for_each(v.begin(), v.end(), myPrint());
    cout << endl;

    reverse(v.begin(), v.end());
    cout << "反转后:" << endl;
    for_each(v.begin(), v.end(), myPrint());
    cout << endl;

}

int main() {
    test();
    return 0;
}